package com.lg.erp.service.impl.zhangchaofu;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lg.erp.entity.zhangchaofu.ZCFTLogistics;
import com.lg.erp.entity.zhangchaofu.TShipping;
import com.lg.erp.entity.zhangchaofu.ZCFTOrder;
import com.lg.erp.mapper.zhangchaofu.TShippingMapper;
import com.lg.erp.service.zhangchaofu.TShippingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class TShippingServiceImpl extends ServiceImpl<TShippingMapper,TShipping> implements TShippingService {
    @Autowired
    private TShippingMapper tShippingMapper;


    @Override
    public IPage<ZCFTOrder> notShippingPage(Page<ZCFTOrder> page) {
        IPage<ZCFTOrder> zcftOrderIPage = tShippingMapper.notShippingPage(page);
        //计算应收金额
        for (int i = 0; i < zcftOrderIPage.getRecords().size(); i++) {
            zcftOrderIPage.getRecords().get(i).setSumPrice(zcftOrderIPage.getRecords().get(i).getPrice()*zcftOrderIPage.getRecords().get(i).getNumber());
        }
        return zcftOrderIPage;
    }

    @Override
    public List<ZCFTLogistics> findLogisticsCompany(String logisticsId) {
        return tShippingMapper.findLogisticsCompany(logisticsId);
    }

    @Override
    public void addSipping(TShipping shipping) {
        String id = UUID.randomUUID().toString().replace("-","").substring(0,20);
        String num = UUID.randomUUID().toString().replace("-","").substring(0,20);
        shipping.setId(id);
        shipping.setShippingNum(num);
        //距离自定义
        shipping.setDistance("666");
        tShippingMapper.insert(shipping);
    }

    @Override
    public TShipping findShipping(String orderId) {
        return tShippingMapper.selectOne(new QueryWrapper<TShipping>().lambda()
                .eq(TShipping::getOrderNum,orderId));
    }
}
